/**
 * 
 */
package de.cbf.cam.dsa.tavern.carte.model.persistence;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

import de.cbf.cam.dsa.tavern.carte.model.entities.MealType;
import de.cbf.cam.dsa.tavern.carte.model.persistence.interfaces.IPersisterMealTypes;
import de.cbf.cam.dsa.tavern.carte.preferences.PreferenceConstants;

/**
 * @author Stefan Alter
 *
 */
public class PersisterXMLMealTypes extends PersisterAbstractXML implements
		IPersisterMealTypes {
	private final String[] MEALTYPE_FILTER_SUFFIXES 	= {"*.mlt.xml","*.*"};
	private final String[] MEALTYPE_FILTER_NAMES 		= {"Mahlzeittypenliste(.mlt.xml)","<Alle Dateien>"};
	/**
	 * 
	 */
	public PersisterXMLMealTypes() {		
	}

	/* (non-Javadoc)
	 * @see de.cbf.cam.dsa.tavern.carte.model.persistence.interfaces.IPersisterMealTypes#getMealTypes()
	 */
	@Override
	public Collection<MealType> getMealTypes() {
		Collection<MealType> resultList = new ArrayList<MealType>();
		//search objects for MealTypes
		Iterator<Object> iterator = getObjects().iterator();
		while (iterator.hasNext()) {
			Object object = (Object) iterator.next();
			if (object instanceof MealType) {
				MealType ingredient = (MealType) object;
				resultList.add(ingredient);
			}
		}
		return resultList;
	}

	/* (non-Javadoc)
	 * @see de.cbf.cam.dsa.tavern.carte.model.persistence.interfaces.IPersisterMealTypes#setMealTypes(java.util.Collection)
	 */
	@Override
	public void setMealTypes(Collection<MealType> mealTypes) {
		setObjects(mealTypes);
	}
	/* (non-Javadoc)
	 * @see de.cbf.cam.dsa.tavern.carte.model.persistence.interfaces.IPersister#getName()
	 */
	@Override
	public String getName() {
		return "Mahlzeittypen, XML-basiert";
	}
	/* (non-Javadoc)
	 * @see de.cbf.cam.dsa.tavern.carte.model.persistence.PersisterAbstractXML#getFileDialogText()
	 */
	@Override
	protected String getFileDialogText() {
		return "Mahlzeittypen bearbeiten";
	}

	/* (non-Javadoc)
	 * @see de.cbf.cam.dsa.tavern.carte.model.persistence.PersisterAbstractXML#getFilterExtensions()
	 */
	@Override
	protected String[] getFilterExtensions() {
		return MEALTYPE_FILTER_SUFFIXES;
	}

	/* (non-Javadoc)
	 * @see de.cbf.cam.dsa.tavern.carte.model.persistence.PersisterAbstractXML#getFilterNames()
	 */
	@Override
	protected String[] getFilterNames() {
		return MEALTYPE_FILTER_NAMES;
	}

	/* (non-Javadoc)
	 * @see de.cbf.cam.dsa.tavern.carte.model.persistence.PersisterAbstract#getEventText()
	 */
	@Override
	protected String getEventText() {
		return "changedMealTypes";
	}

	/* (non-Javadoc)
	 * @see de.cbf.cam.dsa.tavern.carte.model.persistence.PersisterAbstract#getMessageSaveComplete()
	 */
	@Override
	protected String getMessageSaveComplete() {
		return "Mahlzeitypen gespeichert";
	}

	/* (non-Javadoc)
	 * @see de.cbf.cam.dsa.tavern.carte.model.persistence.PersisterAbstract#getMessageLoadComplete()
	 */
	@Override
	protected String getMessageLoadComplete() {
		return "Mahlzeitypen geladen";
	}

	@Override
	protected String getPreferenceNameOfFileName() {
		return PreferenceConstants.P_XML_MEALTYPE_FILE;
	}

}
